//
//  UserCenterViewModel.m
//  ForYourBeauty
//
//  Created by Kelly xu on 2019/6/3.
//  Copyright © 2019 changrenTech. All rights reserved.
//

#import "UserCenterViewModel.h"

@implementation UserCenterViewModel

-(void)fetchUserInfo:(NSString*)userId cmp:(void(^)(UserInfoModel *userModel))cmp{
    [[HttpClient shareClient]get:USERINFO params:@{@"userId":userId} suc:^(id results) {
        cmp([UserInfoModel modelObjectWithDictionary:results]);
    } fail:^(NSString *error, NSInteger status) {
        Toast(error);
    }];
}
-(void)updateUserBirthday:(NSString*)userBirthday
               userWeight:(NSString*)userWeight
             userChildren:(NSString*)userChildren
           userChildbirth:(NSString*)userChildbirth
       userChildbirthType:(NSString*)userChildbirthType
       userMenstrualCycle:(NSString*)userMenstrualCycle
        userMenstrualDays:(NSString*)userMenstrualDays
 userMenstrualLastBeanDay:(NSString*)userMenstrualLastBeanDay
                      cmp:(void(^)())cmp{
    NSMutableDictionary *dic = [[NSMutableDictionary alloc]init];
    if (!EC_ISNullStr([LoginTools sharedTools].userId)) {
        [dic setObject:[LoginTools sharedTools].userId forKey:@"id"];
    }
    if (!EC_ISNullStr(userBirthday)) {
        [dic setObject:userBirthday forKey:@"userBirthday"];
    }
    if (!EC_ISNullStr(userWeight)) {
        [dic setObject:[userWeight stringByReplacingOccurrencesOfString:@"kg" withString:@""] forKey:@"userWeight"];
    }
    if (!EC_ISNullStr(userChildren)) {
        [dic setObject:userChildren forKey:@"userChildren"];
    }
    if (!EC_ISNullStr(userChildbirth)) {
        [dic setObject:userChildbirth forKey:@"userChildbirth"];
    }
    if (!EC_ISNullStr(userChildbirthType)) {
        [dic setObject:userChildbirthType forKey:@"userChildbirthType"];
    }
    if (!EC_ISNullStr(userMenstrualCycle)) {
        [dic setObject:userMenstrualCycle forKey:@"userMenstrualCycle"];
    }
    if (!EC_ISNullStr(userMenstrualDays)) {
        [dic setObject:userMenstrualDays forKey:@"userMenstrualDays"];
    }
    if (!EC_ISNullStr(userMenstrualLastBeanDay)) {
        [dic setObject:userMenstrualLastBeanDay forKey:@"userMenstrualLastBeanDay"];
    }
    [[HttpClient shareClient]postWithUrl:UPDATE_USERINFO params:dic suc:^(id results) {
        [SVProgressHUD dismiss];
        cmp();
    } fail:^(NSString *error, NSInteger status) {
        [SVProgressHUD dismiss];
        Toast(error);
    }];
}
@end
